package com.cykj.finance.service.impl;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;

import com.cykj.common.core.utils.DateUtils;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.common.ocr.IdCardOCR;
import com.cykj.finance.domain.vo.FnCheckVO;
import com.cykj.finance.domain.vo.FnWithdrawVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cykj.finance.mapper.FnWithdrawalRecordsMapper;
import com.cykj.finance.domain.FnWithdrawalRecords;
import com.cykj.finance.service.IFnWithdrawalRecordsService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 提现记录Service业务层处理
 *
 * @author 天才少年
 * @date 2025-08-15
 */
@Service
public class FnWithdrawalRecordsServiceImpl implements IFnWithdrawalRecordsService {
    @Autowired
    private FnWithdrawalRecordsMapper fnWithdrawalRecordsMapper;

    @Autowired
    private IdCardOCR idCardOCR;

    /**
     * 查询提现记录
     *
     * @param id 提现记录主键
     * @return 提现记录
     */
    @Override
    public FnWithdrawalRecords selectBsWithdrawalRecordsById(Long id) {

        System.out.println(fnWithdrawalRecordsMapper.selectBsWithdrawalRecordsById(id));

        return fnWithdrawalRecordsMapper.selectBsWithdrawalRecordsById(id);
    }

    /**
     * 查询提现记录列表
     *
     * @param bsWithdrawalRecords 提现记录
     * @return 提现记录
     */
    @Override
    public List<FnWithdrawalRecords> selectBsWithdrawalRecordsList(FnWithdrawalRecords bsWithdrawalRecords) {
        return fnWithdrawalRecordsMapper.selectBsWithdrawalRecordsList(bsWithdrawalRecords);
    }

    /**
     * 新增提现记录
     *
     * @param fnWithdrawVO 提现记录
     * @return 结果
     */
    @Override
    public int insertBsWithdrawalRecords(FnWithdrawVO fnWithdrawVO) {

        String time = LocalDate.now().toString().replace("-", "");
        String withdrawalNo = "WD" + time + fnWithdrawVO.getShopId();
        fnWithdrawVO.setWithdrawalNo(withdrawalNo);

        return fnWithdrawalRecordsMapper.insertBsWithdrawalRecords(fnWithdrawVO);
    }

    /**
     * 修改提现记录
     *
     * @param bsWithdrawalRecords 提现记录
     * @return 结果
     */
    @Override
    public int updateBsWithdrawalRecords(FnWithdrawalRecords bsWithdrawalRecords) {
        bsWithdrawalRecords.setUpdateTime(DateUtils.getNowDate());
        bsWithdrawalRecords.setCheckTime(DateUtils.getNowDate());
        return fnWithdrawalRecordsMapper.updateBsWithdrawalRecords(bsWithdrawalRecords);
    }

    /**
     * 批量删除提现记录
     *
     * @param ids 需要删除的提现记录主键
     * @return 结果
     */
    @Override
    public int deleteBsWithdrawalRecordsByIds(Long[] ids) {
        return fnWithdrawalRecordsMapper.deleteBsWithdrawalRecordsByIds(ids);
    }

    /**
     * 删除提现记录信息
     *
     * @param id 提现记录主键
     * @return 结果
     */
    @Override
    public int deleteBsWithdrawalRecordsById(Long id) {
        return fnWithdrawalRecordsMapper.deleteBsWithdrawalRecordsById(id);
    }

    @Override
    public String checkIdentity(FnCheckVO fnCheckVO) {
        HashMap<String, String> hashMap = idCardOCR.idCardOcr(fnCheckVO.getIdCardFront());
        if (hashMap.get("姓名").equals(fnCheckVO.getAccountHolder()) && hashMap.get("身份证号码").equals(fnCheckVO.getIdCardNo())) {
            return "身份校验成功";
        }
        return "身份校验失败";
    }
}
